package com.star.rpc.server;

import io.vertx.core.Vertx;

/**
 * packageName com.star.starrpc.server
 *
 * @author zerostart
 * @className VertxHttpServer
 * @date 2024/11/17
 * @description  vertx实现Http服务接口
 */
public class VertxHttpServer implements HttpServer {
    @Override
    public void doStart(int port) {

        Vertx vertx = Vertx.vertx();

        // Create the HTTP server
        vertx.createHttpServer()
                // Handle every request using the router
//                .requestHandler(request -> {
//                    System.out.println("Received request at " + request.method() + " " + request.uri());
//
//                    request.response()
//                            .putHeader("context-type", "application/json")
//                            .end("Hello form Vert.x HttpServer");
//
//                })
                .requestHandler(new HttpServerHandler())
                // Start listening
                .listen(port, result -> {
                    if (result.succeeded()) {
                        System.out.println("server is now Listening  port:" + port);
                    } else {
                        System.out.println("failed to listen on port " + result.cause());
                    }

                });

    }
}
